<?php

namespace App\Http\Controllers;

use App\Models\CommonModel;
use App\Models\MessageNotificationModel;

class WorkbenchController extends Controller
{
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:api', ['except' => []]);
    }

    /**
     * Get a JWT via given credentials.
     * 待处理
     * @return \Illuminate\Http\JsonResponse
     */
    public function pending()
    {
        $member_sub = response()->json(auth('api')->user());
        $member_list = $member_sub->original;

        $credentials = request(['route_type','page']);

        $page = empty($credentials['page'])?0:$credentials['page'];

        $limit = 5;

        if(!empty($credentials['route_type'])){
            $where['route_url'] = $credentials['route_type'];
        }

        $where['notifier_id'] = $member_list['id'];
        $where['is_handled'] = 0;
        $where['type'] = 2;

        $message_array = MessageNotificationModel::where(['notifier_id'=>$member_list['id'],'is_handled'=>0,'type'=>2])->offset($page*$limit)->limit($limit)->get();

        $list = array();

        foreach($message_array as $key=>$val){

            $list[$key] = CommonModel::TypeModelList($val['route_url'],$val['code']);

        }

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$list]);
    }

    /**
     * Get a JWT via given credentials.
     * 我发起的
     * @return \Illuminate\Http\JsonResponse
     */
    public function initiated()
    {
        $member_sub = response()->json(auth('api')->user());
        $member_list = $member_sub->original;

        $message_array = MessageNotificationModel::where(['admin_id'=>$member_list['id'],'is_handled'=>0,'type'=>2])->get();
        $list = array();
        foreach($message_array as $key=>$val){
            $list[$key] = CommonModel::TypeModelList($val['route_url'],$val['code']);
        }

        return response()->json(['code'=>'200','msg' => '请求成功','data'=>$list]);
    }

}
